package com.project.poetry.service.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.project.poetry.service.entity.dto.file.*;
import com.project.poetry.service.entity.po.file.FilePO;
import com.project.poetry.service.entity.po.user.UserPO;
import com.project.poetry.service.service.FileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

/**
 * 文件控制器
 * @author mengxj
 */
@Api("文件")
@RestController
@RequestMapping("file")
public class FileController {

    @Resource
    private FileService fileService;

    @ApiOperation("上传文件")
    @PostMapping("upload")
    public void upload(FileUploadDTO fileUpload, @ApiIgnore UserPO user){
        this.fileService.upload(fileUpload, user);
    }

    @ApiOperation("查询文件")
    @GetMapping("selectList")
    public IPage<FilePO> selectList(FileListDTO fileDto, @ApiIgnore UserPO user){
        return this.fileService.selectList(fileDto, user);
    }

    @ApiOperation("下载文件")
    @GetMapping("download/{id}")
    public void download(@PathVariable("id") Long id, @ApiIgnore HttpServletResponse response){
        this.fileService.download(id, response);
    }

    @ApiOperation("删除文件")
    @DeleteMapping("delete/{id}")
    public void delete(@PathVariable("id") Long id, @ApiIgnore UserPO user){
        this.fileService.delete(id, user);
    }

    @ApiOperation("上传密件")
    @PostMapping("secretUpload")
    public void secretUpload(SecretFileUploadDTO secretFileUpload, @ApiIgnore UserPO user){
        this.fileService.secretUpload(secretFileUpload, user);
    }

    @ApiOperation("密件查询")
    @GetMapping("secretFileList")
    public IPage<SecretFileListOutDTO> secretFileList(SecretFileListDTO secretFileList, @ApiIgnore UserPO user){
        return this.fileService.secretFileList(secretFileList, user);
    }

    @ApiOperation("删除密件")
    @DeleteMapping("deleteSecret/{id}")
    public void deleteSecret(@PathVariable("id") Long id, @ApiIgnore UserPO user){
        this.fileService.deleteSecret(id, user);
    }

    @ApiOperation("下载密件")
    @GetMapping("downloadSecret/{id}")
    public void downloadSecret(@PathVariable("id") Long id, @ApiIgnore HttpServletResponse response){
        this.fileService.downloadSecret(id, response);
    }
}
